package com.zmn.oms.services.impl.conf.attachment;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.oms.model.entity.conf.attachment.ConfOrderAttachment;
import com.zmn.oms.model.entity.conf.attachment.ConfOrderAttachmentCategory;
import com.zmn.oms.model.entity.conf.attachment.ConfOrderAttachmentQuery;
import com.zmn.oms.model.vo.conf.attachment.ConfOrderAttachmentVO;
import com.zmn.oms.persistence.interfaces.conf.attachment.ConfOrderAttachmentDao;
import com.zmn.oms.services.interfaces.conf.attachment.ConfOrderAttachmentCategoryService;
import com.zmn.oms.services.interfaces.conf.attachment.ConfOrderAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 类描述：
 *
 * @author ligang
 * @date 2021/05/06 17:03
 */
@Service
public class ConfOrderAttachmentServiceImpl implements ConfOrderAttachmentService {

    @Resource
    private ConfOrderAttachmentDao confOrderAttachmentDao;

    @Autowired
    private ConfOrderAttachmentCategoryService confOrderAttachmentCategoryService;

    @Override
    public List<ConfOrderAttachment> listByQuery(ConfOrderAttachmentQuery query) {
        List<ConfOrderAttachment> confList = confOrderAttachmentDao.listByQuery(query);
        return confList;
    }

    @Override
    public List<ConfOrderAttachment> listPictureByQuery(ConfOrderAttachmentQuery query) {
        List<ConfOrderAttachment> confList = confOrderAttachmentDao.listPictureByQuery(query);
        return confList;
    }

    @Override
    public List<ConfOrderAttachment> listByQueryAndChannelIdsOrServCategIds(ConfOrderAttachmentQuery query) {
        List<ConfOrderAttachment> confList = confOrderAttachmentDao.listByChannelIdsOrServCategIds(query);
        return confList;
    }

    @Override
    public List<ConfOrderAttachment> listPageByQuery(ConfOrderAttachmentQuery query) {
        query.setTotalCount(confOrderAttachmentDao.countByQuery(query));
        List<ConfOrderAttachment> confList = confOrderAttachmentDao.listPageByQuery(query);
        return confList;
    }

    @Override
    public List<ConfOrderAttachment> listPicturePageByQuery(ConfOrderAttachmentQuery query) {
        query.setTotalCount(confOrderAttachmentDao.countPictureByQuery(query));
        List<ConfOrderAttachment> confList = confOrderAttachmentDao.listPicturePageByQuery(query);
        return confList;
    }



    @Override
    public int countByQuery(ConfOrderAttachmentQuery query) {
        return confOrderAttachmentDao.countByQuery(query);
    }

    @Override
    public ConfOrderAttachmentVO findConfById(Integer id) {
        ConfOrderAttachment confOrderAttachment = confOrderAttachmentDao.selectByPrimaryKey(id);
        ConfOrderAttachmentVO confOrderAttachmentVO = BeanMapper.map(confOrderAttachment, ConfOrderAttachmentVO.class);
        ConfOrderAttachmentCategory category = confOrderAttachmentCategoryService.findCategoryById(confOrderAttachment.getCategId());
        confOrderAttachmentVO.setCategName(category.getCategName());
        return confOrderAttachmentVO;
    }

    @Override
    public ConfOrderAttachment findById(Integer id) {
        return confOrderAttachmentDao.selectByPrimaryKey(id);
    }

    @Override
    public void updateConfById(ConfOrderAttachment conf) {
        Objects.requireNonNull(conf.getId(), "ID不能为空");
        conf.setUpdateTime(DateUtil.getNow());
        confOrderAttachmentDao.updateByPrimaryKeySelective(conf);
    }

    @Override
    public Integer insertConf(ConfOrderAttachment conf) {
        conf.setCreateTime(DateUtil.getNow());
        return confOrderAttachmentDao.insertSelective(conf);
    }

    @Override
    public Integer deleteById(Integer id) {
        return confOrderAttachmentDao.deleteByPrimaryKey(id);
    }

}
